#include <bits/stdc++.h>
using namespace std;
class Node{
public:
    int data;
    Node* pNext;
    Node(int d,Node* n = nullptr)
    {
        data = d;
        pNext = n;
    }
};
Node* ReverseList(Node* pHead)
{
    Node* pCurrent = pHead;
    Node* pReversed = nullptr;
    Node* pPrenode = nullptr;
    while(pCurrent)
    {
        Node* pNext = pCurrent->pNext;
        //如果到了最后一个节点，返回最后一个节点pReversed
        if(pNext==nullptr)
            pReversed = pCurrent;
        //当前节点指向当前节点的前一个节点
        pCurrent->pNext = pPrenode;
        //当前节点的前一个节点变成当前节点
        pPrenode = pCurrent;
        //当前节点的后一个节点变成当前节点
        pCurrent = pNext;
    }
    return pReversed;
}
int main() {
    Node* a = new Node(3);
    Node* b = new Node(4);
    Node* c = new Node(5);
    Node* d = new Node(6);
    a->pNext = b;
    b->pNext = c;
    c->pNext = d;
    Node* re = ReverseList(a);
    while(re)
    {
        cout<<re->data;
        re = re->pNext;
    }
    delete a,b,c,d,re;
    return 0;
}
